package com.beidasoft.web.vo.system;

import com.beidasoft.web.model.system.Organization;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.List;

/**
 * Created by hoax on 2016/8/11.
 */
public class OrganizationAttributeBean {
    private Integer administrativeFlag;         //行政区划标识   1市级  2区级
    private Integer natureFlag;                 //部门性质标识   1监督  2执法
    private String id;                          //id条件

    public Integer getNatureFlag() {
        return natureFlag;
    }

    public void setNatureFlag(Integer natureFlag) {
        this.natureFlag = natureFlag;
    }

    public Integer getAdministrativeFlag() {
        return administrativeFlag;
    }

    public void setAdministrativeFlag(Integer administrativeFlag) {
        this.administrativeFlag = administrativeFlag;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public static JSONArray organizationListToJSONArray(List<Organization> organizationList) {
        JSONArray resultArray = new JSONArray();
        if (organizationList != null && organizationList.size() > 0) {
            for (Organization organization : organizationList) {
                JSONObject organizationJSONObject = new JSONObject();
                organizationJSONObject.put("children", false);
                organizationJSONObject.put("id", String.valueOf(organization.getId()));
                organizationJSONObject.put("icon", organization.getIcon());
                organizationJSONObject.put("text", organization.getName());
                resultArray.add(organizationJSONObject);
            }
        }
        return resultArray;
    }

    public static JSONArray orgListToJSONArrayWithCheck(List<Organization> organizationList, List<String> relationOrgIds) {
        JSONArray resultArray = new JSONArray();
        if (organizationList != null && organizationList.size() > 0) {
            for (Organization organization : organizationList) {
                JSONObject organizationJSONObject = new JSONObject();
                if (relationOrgIds.contains(organization.getId())) {
                    JSONObject state = new JSONObject();
                    state.put("selected", true);
                    organizationJSONObject.put("state", state);
                }
                organizationJSONObject.put("children", false);
                organizationJSONObject.put("id", String.valueOf(organization.getId()));
                organizationJSONObject.put("icon", organization.getIcon());
                organizationJSONObject.put("text", organization.getName());
                resultArray.add(organizationJSONObject);
            }
        }
        return resultArray;
    }
}
